<?php
namespace app\common\behavior;
use think\Exception;
use think\Lang;
use think\Loader;

class Cashing 
{
    public function afterApplyCash(&$info)
    {
        try {
            $notice_instance = \services\notices\Notice::instance();
            $user_info       = $this->getUserInfo($info['user_id']);
            $managers        = $user_info->camp->managers;
            foreach ($managers as $manager) {
                $recipients['sign'][] = $manager->sign;
            }
            //发送通知信息给管理员
            $notice_instance->send($recipients, Lang::get('Application for withdrawal'), Lang::get('Application for withdrawal'));
            
        } catch (\Exception $e) {
            
        }
    }

	/**
     * [afterCompleteCash description]
     * @param  [type] &$info [description]
     * @return [type]        [description]
     */
    public function afterCompleteCash(&$info)
    {
    	try {
            $notice_instance = \services\notices\Notice::instance();
            $user_info       = $this->getUserInfo($info['user_id']);

            if ($user_info->email) {
                $recipients['mail'] = $user_info->email;
                //$notice_instance->mail->send($user_info->email, Lang::get('Your cash withdrawal has been completed'));
            }

            $recipients['sign'] = $user_info->sign;

            $notice_instance->send($recipients, Lang::get('Your cash withdrawal has been completed'), Lang::get('Your cash withdrawal has been completed'));
    	} catch (\Exception $e) {
    		
    	}
        
    }

    /**
     * [afterRefusedCash description]
     * @param  [type] &$info [description]
     * @return [type]        [description]
     */
    public function afterRefusedCash(&$info)
    {
        try {
            $notice_instance = \services\notices\Notice::instance();
            $user_info       = $this->getUserInfo($info['user_id']);

            if ($user_info->email) {
                $recipients['mail'] = $user_info->email;
            }

            $recipients['sign'] = $user_info->sign;

            $notice_instance->send($recipients, Lang::get('Cash withdrawal was rejected'), Lang::get('Cash withdrawal was rejected'));
            
        } catch (\Exception $e) {
            
        }
    }

    public function afterFailedCash(&$info)
    {
        try {
            $notice_instance = \services\notices\Notice::instance();
            $user_info       = $this->getUserInfo($info['user_id']);

            if ($user_info->email) {
                $recipients['mail'] = $user_info->email;
            }

            $recipients['sign'] = $user_info->sign;

            $notice_instance->send($recipients, Lang::get('Cash withdrawal failure'), Lang::get('Cash withdrawal failure'));
            
        } catch (\Exception $e) {
            
        }
    }

    protected function getUserInfo($user_id)
    {
        return Loader::model('common/Users')->getUserInfo($user_id);
    }
}